﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;
using System.Net;

using EHTWebsite.Code;
using EHTWebsiteProject.Code.BLL;
using System.Resources;
using System.Threading;
using System.Globalization;
using System.Text;
using Telerik.Web.UI;
using System.Collections.Generic;
using EHTWebsiteProject.Code.Entity;

namespace EHTWebsiteProject.Administrator
{
    public partial class EHTConfigCategoryNews : System.Web.UI.Page
    {
        public Boolean IsVN = true;
        private String Loai = "";
        private String languageCode = "vi-VN";
        private ResourceManager rm = new ResourceManager("Resources.SiteMap", System.Reflection.Assembly.Load("App_GlobalResources"));

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {

                try
                {
                    languageCode = Session[HangSo.LANGUAGE_CODE].ToString();
                    if (languageCode == "en-us")
                    {
                        IsVN = false;
                    }

                }
                catch (Exception ex)
                {
                }

                Thread.CurrentThread.CurrentCulture = new CultureInfo(languageCode);
                LoadLanguage(Thread.CurrentThread.CurrentCulture);
            }
        }

        /// <summary>
        /// Ham load ngon ngu
        /// </summary>
        /// <param name="ci"></param>
        public void LoadLanguage(CultureInfo ci)
        {
            lbSave.Text = rm.GetString("lbSave", ci);
            lbBack.Text = rm.GetString("lbBack", ci);
            lbParameters_Advanced.Text = rm.GetString("lbParameters_Advanced", ci);
            lbParameters_Basic.Text = rm.GetString("lbParameters_Basic", ci);
        }

        /// <summary>
        /// Ham lay cac tham so
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public ParaGroupNews GetParagroupNews(ParaGroupNews theParaGroupNews)
        {
            theParaGroupNews.NewsOrder = "";           
                theParaGroupNews.NewsName = rbTenNhom_Show.Checked.ToString();
                theParaGroupNews.Desciption = rbMoTa_Show.Checked.ToString();
            try
            {
                theParaGroupNews.NumIntro = Int32.Parse(txtNumIntro.Text);
            }
            catch
            {
                theParaGroupNews.NumIntro = 1;
            }

            try
            {
                theParaGroupNews.Columns = Int32.Parse(txtColumns.Text);
            }
            catch
            {
                theParaGroupNews.Columns = 1;
            }
            theParaGroupNews.DisplayIntroText = rbDisplay_Yes.Checked.ToString();
            theParaGroupNews.DisplayLinkReamore = rbReadmore_Yes.Checked.ToString();                     
            theParaGroupNews.DisplayThumbnail = rbthum_Yes.Checked.ToString();          
            theParaGroupNews.NumChar = txtNumChar.Text;
            theParaGroupNews.WidthOfThumb = txtWidthOfthumbs.Text;
            theParaGroupNews.ImgAlign = "";
            theParaGroupNews.Pagination = "";
            theParaGroupNews.Hover = "";
            return theParaGroupNews;
        }


        public void DanhMucCon(Int32 DanhMucTinTucID)
        {
            DataSet ds = DanhMucTinTucProvider.GetDanhMucTinTucsByParentID(DanhMucTinTucID); // lấy tất cả danh mục con theo ID danh mục cha 

            if (ds.Tables[0].Rows.Count > 0)
            {
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    ParaGroupNews theParaGroupNews = new ParaGroupNews();
                    ParaGroupNews theGroupNews = new ParaGroupNews();
                    theParaGroupNews = GetParagroupNews(theGroupNews);
                    theParaGroupNews.ParaGroupNewsID = Int32.Parse(ds.Tables[0].Rows[i]["DanhMucTinTucID"].ToString());
                    ThamSoProvider.UpdateParaGroupNews(theParaGroupNews);
                   
                }
            }
        }
      
    

        protected void imgSave_Click(object sender, ImageClickEventArgs e)
        {
            // lấy giá trị trên sesion  gán vào mảng
            ArrayList arr = (ArrayList)Session["ArrayListConfig"];
            for (int i = 0; i < arr.Count; i++)
            {
                ParaGroupNews theParaGroupNews = new ParaGroupNews();
                ParaGroupNews theGroupNews = new ParaGroupNews();
                theParaGroupNews = GetParagroupNews(theGroupNews);
                theParaGroupNews.ParaGroupNewsID = Int32.Parse(arr[i].ToString());
                ThamSoProvider.UpdateParaGroupNews(theParaGroupNews);

                DanhMucCon(Int32.Parse(arr[i].ToString()));
            }

            Response.Redirect("EHTCategoryNews.aspx");
        }
    }
}